using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VKDTAX
    {
        public DataRow Convert2KDTAX(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKDTAX(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KDXMANDANT"] = " ".PadRight(2 ); 
         dwReturn["KDXKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["KDXVB"] = " ".PadRight(3 ); 
         dwReturn["KDXADRSL"] = " ".PadRight(8 ); 
         dwReturn["KDXTAXNR1"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT1"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL1"] = " ".PadRight(2 ); 
         dwReturn["KDXTAXNR2"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT2"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL2"] = " ".PadRight(2 ); 
         dwReturn["KDXTAXNR3"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT3"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL3"] = " ".PadRight(2 ); 
         dwReturn["KDXTAXNR4"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT4"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL4"] = " ".PadRight(2 ); 
         dwReturn["KDXTAXNR5"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT5"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL5"] = " ".PadRight(2 ); 
         dwReturn["KDXTAXNR6"] = " ".PadRight(20 ); 
         dwReturn["KDXTAXDAT6"] = " ".PadRight(0 ); 
         dwReturn["KDXTAXCL6"] = " ".PadRight(2 ); 
         dwReturn["KDXFILLER"] = " ".PadRight(47 ); 
         dwReturn["KDXAENZL"] = " ".PadRight(0 ); 
         dwReturn["KDXAENB"] = " ".PadRight(8 ); 
         dwReturn["KDXAEND"] = " ".PadRight(0 ); 
         dwReturn["KDXNEUB"] = " ".PadRight(8 ); 
         dwReturn["KDXNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKDTAX(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveKDTAX(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryKDTAX(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapKDTAX(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertKDTAX(dwLocal, ITXDBVERSION);
            }
            UpdateKDTAX(dwLocal);
        }
        public void InsertKDTAX(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO KDTAX(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryKDTAX(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KDTAX WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM KDTAX  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "KDTAX";
            Return = Result;
            return Return;
        }
        public void DeleteKDTAX(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KDTAX   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateKDTAX(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE KDTAX SET "
                    +"KDXMANDANT= :KDXMANDANT,"
                    +"KDXKUNDNR= :KDXKUNDNR,"
                    +"KDXVB= :KDXVB,"
                    +"KDXADRSL= :KDXADRSL,"
                    +"KDXTAXNR1= :KDXTAXNR1,"
                    +"KDXTAXDAT1= :KDXTAXDAT1,"
                    +"KDXTAXCL1= :KDXTAXCL1,"
                    +"KDXTAXNR2= :KDXTAXNR2,"
                    +"KDXTAXDAT2= :KDXTAXDAT2,"
                    +"KDXTAXCL2= :KDXTAXCL2,"
                    +"KDXTAXNR3= :KDXTAXNR3,"
                    +"KDXTAXDAT3= :KDXTAXDAT3,"
                    +"KDXTAXCL3= :KDXTAXCL3,"
                    +"KDXTAXNR4= :KDXTAXNR4,"
                    +"KDXTAXDAT4= :KDXTAXDAT4,"
                    +"KDXTAXCL4= :KDXTAXCL4,"
                    +"KDXTAXNR5= :KDXTAXNR5,"
                    +"KDXTAXDAT5= :KDXTAXDAT5,"
                    +"KDXTAXCL5= :KDXTAXCL5,"
                    +"KDXTAXNR6= :KDXTAXNR6,"
                    +"KDXTAXDAT6= :KDXTAXDAT6,"
                    +"KDXTAXCL6= :KDXTAXCL6,"
                    +"KDXFILLER= :KDXFILLER,"
                    +"KDXAENZL= :KDXAENZL,"
                    +"KDXAENB= :KDXAENB,"
                    +"KDXAEND= :KDXAEND,"
                    +"KDXNEUB= :KDXNEUB,"
                    +"KDXNEUD= :KDXNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KDXMANDANT", OracleType.NVarChar).Value = dwData["KDXMANDANT"].ToString(); 
          or1.Parameters.Add("KDXKUNDNR", OracleType.NVarChar).Value = dwData["KDXKUNDNR"].ToString(); 
          or1.Parameters.Add("KDXVB", OracleType.NVarChar).Value = dwData["KDXVB"].ToString(); 
          or1.Parameters.Add("KDXADRSL", OracleType.NVarChar).Value = dwData["KDXADRSL"].ToString(); 
          or1.Parameters.Add("KDXTAXNR1", OracleType.NVarChar).Value = dwData["KDXTAXNR1"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT1", OracleType.NVarChar).Value = dwData["KDXTAXDAT1"].ToString(); 
          or1.Parameters.Add("KDXTAXCL1", OracleType.NVarChar).Value = dwData["KDXTAXCL1"].ToString(); 
          or1.Parameters.Add("KDXTAXNR2", OracleType.NVarChar).Value = dwData["KDXTAXNR2"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT2", OracleType.NVarChar).Value = dwData["KDXTAXDAT2"].ToString(); 
          or1.Parameters.Add("KDXTAXCL2", OracleType.NVarChar).Value = dwData["KDXTAXCL2"].ToString(); 
          or1.Parameters.Add("KDXTAXNR3", OracleType.NVarChar).Value = dwData["KDXTAXNR3"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT3", OracleType.NVarChar).Value = dwData["KDXTAXDAT3"].ToString(); 
          or1.Parameters.Add("KDXTAXCL3", OracleType.NVarChar).Value = dwData["KDXTAXCL3"].ToString(); 
          or1.Parameters.Add("KDXTAXNR4", OracleType.NVarChar).Value = dwData["KDXTAXNR4"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT4", OracleType.NVarChar).Value = dwData["KDXTAXDAT4"].ToString(); 
          or1.Parameters.Add("KDXTAXCL4", OracleType.NVarChar).Value = dwData["KDXTAXCL4"].ToString(); 
          or1.Parameters.Add("KDXTAXNR5", OracleType.NVarChar).Value = dwData["KDXTAXNR5"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT5", OracleType.NVarChar).Value = dwData["KDXTAXDAT5"].ToString(); 
          or1.Parameters.Add("KDXTAXCL5", OracleType.NVarChar).Value = dwData["KDXTAXCL5"].ToString(); 
          or1.Parameters.Add("KDXTAXNR6", OracleType.NVarChar).Value = dwData["KDXTAXNR6"].ToString(); 
          or1.Parameters.Add("KDXTAXDAT6", OracleType.NVarChar).Value = dwData["KDXTAXDAT6"].ToString(); 
          or1.Parameters.Add("KDXTAXCL6", OracleType.NVarChar).Value = dwData["KDXTAXCL6"].ToString(); 
          or1.Parameters.Add("KDXFILLER", OracleType.NVarChar).Value = dwData["KDXFILLER"].ToString(); 
          or1.Parameters.Add("KDXAENZL", OracleType.NVarChar).Value = dwData["KDXAENZL"].ToString(); 
          or1.Parameters.Add("KDXAENB", OracleType.NVarChar).Value = dwData["KDXAENB"].ToString(); 
          or1.Parameters.Add("KDXAEND", OracleType.NVarChar).Value = dwData["KDXAEND"].ToString(); 
          or1.Parameters.Add("KDXNEUB", OracleType.NVarChar).Value = dwData["KDXNEUB"].ToString(); 
          or1.Parameters.Add("KDXNEUD", OracleType.NVarChar).Value = dwData["KDXNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
